{% extends "base.html" %}

{% block title %}
  <title>
    {{ domain.name | pretty_domain_name }} - {{ SITE_NAME }}
  </title>
{% endblock %}

{% block dashboard_stat %}
<div class="content-header">
  <div class="container-fluid">
    <div class="row mb-2">
      <div class="col-sm-6">
        <h1 class="m-0 text-dark">
          {% if record_name and record_type %}
          Record changelog: <b>{{ record_name}} &nbsp {{ record_type }}</b>
          {% else %}
          Zone changelog: <b>{{ domain.name | pretty_domain_name }}</b>
          {% endif %}
        </h1>
      </div>
      <div class="col-sm-6">
        <ol class="breadcrumb float-sm-right">
          <li class="breadcrumb-item"><a href="{{ url_for('dashboard.dashboard') }}">Dashboard</a></li>
          <li class="breadcrumb-item active">Changelog: {{ domain.name | pretty_domain_name }}</li>
        </ol>
      </div>
    </div>
  </div>
</div>
{% endblock %}

{% import 'applied_change_macro.html' as applied_change_macro %}

{% block content %}
<section class="content">
  <div class="container-fluid">
    <div class="row">
      <div class="col-12">
        <div class="card">
          <div class="card-body">
            <button type="button" class="btn btn-primary float-left button_show_records" id="{{ domain.name }}">
              <i class="fa-solid fa-arrow-left"></i>          
              &nbsp;Manage Zone {{ domain.name }}
            </button>
          </div>
          <div class="card-body">
            <table id="tbl_changelog" class="table table-bordered table-striped">
              <thead>
                <tr>
                  <th>Changed on</th>
                  <th>Name</th>
                  <th>Type</th>
                  <th>TTL</th>
                  <th>Data</th>
                  <th>Status</th>
                  <th>Comment</th>
                  <th>Changed by</th>
                </tr>
              </thead>
              <tbody>
                {% for applied_change in allHistoryChanges %}
                  <tr class="odd row_record" id="{{ domain.name }}">
                    <td id="changed_on" class="changed_on">
                      {{ applied_change.history_entry.created_on }}
                    </td>
                    {% call applied_change_macro.applied_change_template(applied_change) %}
                    {% endcall %}
                    <td>
                      {{ applied_change.history_entry.created_by }}
                    </td>
                  </tr>
                {% endfor %}
              </tbody>
            </table>
          </div>
        </div>
      </div>
    </div>
  </div>
</section>
{% endblock %}

{% block extrascripts %}
<script>
    // handle "show records" button
    $(document.body).on("click", ".button_show_records", function (e) {
        e.stopPropagation();
        window.location.href = "/domain/{{domain.name}}";
    });

    var coll = document.getElementsByClassName("collapsible");
    var i;

    for (i = 0; i < coll.length; i++) {
        coll[i].addEventListener("click", function () {
            this.classList.toggle("active");
            var content = this.nextElementSibling;
            if (content.style.maxHeight) {
                content.style.maxHeight = null;
            } else {
                content.style.maxHeight = content.scrollHeight + "px";
            }
        });
    }

    var els = document.getElementsByClassName("changed_on");
    for (var i = 0; i < els.length; i++) {
        // els[i].innerHTML = moment.utc(els[i].innerHTML).local().format('YYYY-MM-DD HH:mm:ss');
        els[i].innerHTML = moment.utc(els[i].innerHTML,'YYYY-MM-DD HH:mm:ss').local().format('YYYY-MM-DD HH:mm:ss');
    }

</script>
{% endblock %}
